package com.superc.lib.intent;

import com.superc.lib.helper.ResourceHelper;
import com.superc.lib.ui.UIFunction;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class IntentFunction {
	
	public static Intent getDirectIntent(Context view,Class<?> targetClass){
		Intent activityIntent=new Intent();
		activityIntent.setClass(view, targetClass);
		return activityIntent;
	}
	
	public static Bundle getBundle(Activity activity){
		Intent intent=activity.getIntent();
		if(intent==null) 
			return null;
		else
			return intent.getExtras();
	}
	
	public static void openFile(Activity activity,Uri fileUri){
		try{
			Intent intent=new Intent();
			intent.setAction("android.intent.action.VIEW"); 
		    intent.setDataAndType(fileUri,ResourceHelper.getMimeType(fileUri.getPath()) ); 
		    activity.startActivity(intent);
		}
		catch(ActivityNotFoundException e){
			UIFunction.ShowMessage(activity, "Error", e.getMessage());
		}
	}
}
